//
//  OrientationExampleViewController.m
//  OrientationExample
//

#import "OrientationExampleViewController.h"

@implementation OrientationExampleViewController

- (NSString *)getOrientationName {
	switch (self.interfaceOrientation) {
		case UIInterfaceOrientationPortrait:
			return @"Portrait";
			break;
			
		case UIInterfaceOrientationPortraitUpsideDown:
			return @"Portrait (upside down)";
			break;
			
		case UIInterfaceOrientationLandscapeLeft:
			return @"Landscape (left)";
			break;

		case UIInterfaceOrientationLandscapeRight:
			return @"Landscape (right)";
			break;
	}
	
	return @"Unknown";
}

- (void)viewDidLoad {
    [super viewDidLoad];
	
	CGRect labelFrame = CGRectMake(10,10,300,38);
	orientationLabel = [[UILabel alloc] initWithFrame:labelFrame];
	orientationLabel.textAlignment = UITextAlignmentCenter;
	orientationLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
	orientationLabel.text = [self getOrientationName];
	
	[self.view addSubview:orientationLabel];
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
	orientationLabel.text = [self getOrientationName];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)dealloc {
	[orientationLabel release];
    [super dealloc];
}

@end
